home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / tcp / mufs_telnetd.lha / telnetd2_0.lha / telnetd-2.0 / source / fakesr / fakesr.c < prev    next >
C/C++ Source or Header  |  1995-01-15  |  5KB  |  187 lines

  1. #include <exec/types.h>
  2. #include <exec/io.h>
  3. #include <exec/errors.h>
  4. #include <exec/devices.h>
  5. #include <proto/exec.h>
  6.  
  7. #include "fakesr.h"
  8. #include "fakesrprivate.h"
  9.  
  10. #define NewList(list) {(list)->lh_Head=(struct Node *)&(list)->lh_Tail;(list)->lh_TailPred=(struct Node *)&(list)->lh_Head;(list)->lh_Tail=NULL;}
  11.  
  12. ULONG __asm _FakeSer_BeginIO(register __a1 void *IORequest,register __a6 struct FakeSerDevice *FakeSerBase)
  13. {
  14.     struct FSRUnit *Unit;
  15.     Unit=(struct FSRUnit *)((struct IORequest *)IORequest)->io_Unit;
  16.     if (!Unit || !Unit->fsru_BeginIO) return 0;
  17.     return Unit->fsru_BeginIO(IORequest);
  18. }
  19.  
  20. ULONG __asm _FakeSer_AbortIO(register __a1 void *IORequest,register __a6 struct FakeSerDevice *FakeSerBase)
  21. {
  22.     struct FSRUnit *Unit;
  23.     Unit=(struct FSRUnit *)((struct IORequest *)IORequest)->io_Unit;
  24.     if (!Unit || !Unit->fsru_AbortIO) return 0;
  25.     return Unit->fsru_AbortIO(IORequest);
  26. }
  27.  
  28. int AddUnit(struct FakeSerDevice *FakeSerBase,struct FSRUnit *Unit)
  29. /* returns zero for no error */
  30. /* returns 1 for bad address/other mem error */
  31. /* returns to for non-uniqe unit */
  32. {
  33.     struct FSRUnit *CurUnit;
  34.     void *SysBase;
  35.  
  36.   SysBase=*((void **)0x00000004);
  37.  
  38.     if (!FakeSerBase || !Unit) return 1;
  39.     for (CurUnit=(struct FSRUnit *)FakeSerBase->fsd_UnitList.lh_Head;
  40.         CurUnit->fsru_Node.ln_Succ && CurUnit->fsru_Num != Unit->fsru_Num;
  41.         CurUnit=(struct FSRUnit *)CurUnit->fsru_Node.ln_Succ);
  42.     
  43.     if (CurUnit->fsru_Node.ln_Succ) {
  44.         /* we have a duplicated unit # */
  45.         return 2;
  46.         
  47.     }
  48.     else AddTail(&FakeSerBase->fsd_UnitList,Unit);
  49.     return 0;
  50. }
  51.  
  52. ULONG CtlUnit_BeginIO(void *IORequest)
  53. {
  54.     struct IOStdReq *IOReq;
  55.     struct FakeSerDevice *FakeSerBase;
  56.     struct FSRUnit *Unit;
  57.     int Err;
  58.     
  59.     void *SysBase;
  60.  
  61.   SysBase=*((void **)0x00000004);
  62.     
  63.     if (!IORequest) return 0;
  64.     
  65.     IOReq=IORequest;
  66.     FakeSerBase=(struct FakeSerDevice *)IOReq->io_Device;
  67.     if (!FakeSerBase) return 0;
  68.     
  69.     if (IOReq->io_Flags & IOF_QUICK) {
  70.         IOReq->io_Flags &= ~(IOF_QUICK);
  71.         /* we don't explicitly support quick io */
  72.     }
  73.     IOReq->io_Error=0;
  74.     switch (IOReq->io_Command) {
  75.         case FSRCMD_ADDUNIT:
  76.             Unit=(struct FSRUnit *)IOReq->io_Data;
  77.             if (Unit->fsru_Num == FSR_UNITNONE) {
  78.                 Forbid();
  79.                 for (Unit->fsru_Num=MAXRESERVEDUNIT+1;(Err=AddUnit(FakeSerBase,Unit))==2;Unit->fsru_Num++)
  80.                     ;
  81.                 Permit();
  82.             } else {
  83.                 Forbid();
  84.                 Err=AddUnit(FakeSerBase,Unit);
  85.                 Permit();
  86.             }
  87.             if (Err) {
  88.                 if (Err==1) IOReq->io_Error=IOERR_BADADDRESS;
  89.                 else IOReq->io_Error=FSRCTLERR_NONUNIQUE;
  90.             }
  91.             ReplyMsg(&IOReq->io_Message);
  92.         break;
  93.         
  94.         case FSRCMD_REMUNIT:
  95.             Unit=(struct FSRUnit *)IOReq->io_Data;
  96.             Forbid();
  97.             Remove(Unit);
  98.             Permit();
  99.             ReplyMsg(&IOReq->io_Message);
  100.         break;
  101.         
  102.         default:
  103.           IOReq->io_Error=IOERR_NOCMD;
  104.             ReplyMsg(&IOReq->io_Message);
  105.             
  106.     }
  107. }
  108.  
  109. ULONG CtlUnit_AbortIO(void *IORequest)
  110. {
  111.     return 0; /* We do stuff quickly anyway */    
  112. }
  113.  
  114.  
  115.  
  116. void __saveds __asm _UserLibInit(register __a6 struct FakeSerDevice *FakeSerBase )
  117. {
  118.     void *SysBase;
  119.  
  120.   SysBase=*((void **)0x00000004);
  121.  
  122.     if (!FakeSerBase) return;
  123.     NewList(&FakeSerBase->fsd_UnitList);
  124.     FakeSerBase->fsd_CtlUnit.fsru_Num=FSR_CTLUNIT;
  125.     FakeSerBase->fsd_CtlUnit.fsru_BeginIO=CtlUnit_BeginIO;
  126.     FakeSerBase->fsd_CtlUnit.fsru_AbortIO=CtlUnit_AbortIO;
  127.     FakeSerBase->fsd_CtlUnit.fsru_Open=NULL;
  128.     FakeSerBase->fsd_CtlUnit.fsru_Close=NULL;
  129.     Forbid(); /* Lock the list */
  130.     AddUnit(FakeSerBase,&FakeSerBase->fsd_CtlUnit);
  131.     Permit();
  132. }
  133.  
  134. void __saveds __asm _UserLibCleanup(register __a6 struct FakeSerDevice *FakeSerBase)
  135. {
  136.     return; /* No cleanup work required */
  137. }
  138.  
  139. void __saveds _UserLibOpen(struct FakeSerDevice *FakeSerBase, void *IORequest, LONG UnitNum,LONG Flags)
  140. {
  141.     struct FSRUnit *Unit;
  142.     struct IORequest *IOReq;
  143.     void *SysBase;
  144.  
  145.   SysBase=*((void **)0x00000004);
  146.  
  147.     IOReq=IORequest;
  148.     if (!IOReq) return;
  149.     IOReq->io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  150.     
  151.     Forbid(); /* We Forbid()-protect the unit list */
  152.     for (Unit=(struct FSRUnit *)FakeSerBase->fsd_UnitList.lh_Head;Unit->fsru_Node.ln_Succ;Unit=(struct FSRUnit *)Unit->fsru_Node.ln_Succ)
  153.         if (Unit->fsru_Num==UnitNum) {
  154.             IOReq->io_Unit=(struct Unit *)Unit;
  155.             if (Unit->fsru_Open) Unit->fsru_Open(IORequest);
  156.             Permit();
  157.             return;
  158.         }
  159.     Permit();
  160.     
  161.     IOReq->io_Error=IOERR_OPENFAIL;
  162.     IOReq->io_Device=NULL;
  163.     
  164. }
  165.  
  166. void __saveds _UserLibClose(struct FakeSerDevice *FakeSerBase,void *IORequest)
  167. {
  168.     struct FSRUnit *Unit;
  169.     struct IORequest *IOReq;
  170.     void *SysBase;
  171.  
  172.   SysBase=*((void **)0x00000004);
  173.     
  174.     if (!FakeSerBase || !IORequest) return;
  175.     IOReq=IORequest;
  176.     
  177.     Unit=(struct FSRUnit *)IOReq->io_Unit;
  178.     if (!Unit) return;
  179.     
  180.     if (Unit->fsru_Close) Unit->fsru_Close(IORequest);
  181.     return;
  182. }
  183.  
  184.  
  185.  
  186.  
  187.